package xmarti.vacaxm.beans.maintenance;

import java.util.Objects;

public class AnimalCode implements java.io.Serializable {
	/*
            Estructura Codi RIIA
            2 digits alfanumèrics de Pais
            2 digits de control
            2 digits per la comunitat autonoma
            8 (4+4) digits per l'identificació de l'animal.
        */
        private int id=-1;
        private Country country;
	private String controlCode;
	private Area areaCode;
	private String animalCode1;
        private String animalCode2;
	public AnimalCode(){
		areaCode= new Area();
		country= new Country(); 
	}
        
	public AnimalCode(Country country, String controlCode, Area areaCode,
			String animalCode1, String animalCode2) {
		super();
		this.country = country;
		this.controlCode = controlCode;
		this.areaCode = areaCode;
		this.animalCode1 = animalCode1;
                this.animalCode2 = animalCode2;
	}

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }
	
        
        /**
	 * @return the country
	 */
	public Country getCountry() {
		return country;
	}
	/**
	 * @param country the country to set
	 */
	public void setCountry(Country country) {
		this.country = country;
	}
	/**
	 * @return the controlCode
	 */
	public String getControlCode() {
		return controlCode;
	}
	/**
	 * @param controlCode the controlCode to set
	 */
	public void setControlCode(String controlCode) {
		this.controlCode = controlCode;
	}
	/**
	 * @return the areaCode
	 */
	public Area getAreaCode() {
		return areaCode;
	}
	/**
	 * @param areaCode the areaCode to set
	 */
	public void setAreaCode(Area areaCode) {
		this.areaCode = areaCode;
	}

    public String getAnimalCode1() {
        return animalCode1;
    }

    public void setAnimalCode1(String animalCode1) {
        this.animalCode1 = animalCode1;
    }

    public String getAnimalCode2() {
        return animalCode2;
    }

    public void setAnimalCode2(String animalCode2) {
        this.animalCode2 = animalCode2;
    }

    @Override
    public int hashCode() {
//        int hash = 3;
//        hash = hash + this.country.hashCode();
//        hash = hash + this.controlCode.hashCode();
//        hash = hash + this.areaCode.hashCode();
//        hash = hash + this.animalCode1.hashCode();
//        hash = hash + this.animalCode2.hashCode();
//        return hash;
        return this.id; 
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
//        if (getClass() != obj.getClass()) {
//            return false;
//        }
        final AnimalCode other = (AnimalCode) obj;
//        if (!Objects.equals(this.country, other.country)) {
//            return false;
//        }
//        if (!Objects.equals(this.controlCode, other.controlCode)) {
//            return false;
//        }
//        if (!Objects.equals(this.areaCode, other.areaCode)) {
//            return false;
//        }
//        if (!Objects.equals(this.animalCode1, other.animalCode1)) {
//            return false;
//        }
//        if (!Objects.equals(this.animalCode2, other.animalCode2)) {
//            return false;
//        }
          if (this.id!=other.id) {
            return false;
        }
        return true;
    }
            
        public boolean equals(AnimalCode obj) {
        if (obj == null) {
            return false;
        }
        
//        if (getClass() != obj.getClass()) {
//            return false;
//        }
        final AnimalCode other = (AnimalCode) obj;
        if (!Objects.equals(this.country, other.country)) {
            return false;
        }
        if (!Objects.equals(this.controlCode, other.controlCode)) {
            return false;
        }
        if (!Objects.equals(this.areaCode, other.areaCode)) {
            return false;
        }
        if (!Objects.equals(this.animalCode1, other.animalCode1)) {
            return false;
        }
        if (!Objects.equals(this.animalCode2, other.animalCode2)) {
            return false;
        }
        return true;
    }

    
    
        @Override
     public String toString(){
         if(this.animalCode2==null ) return "-";    
         return this.country.getCode()+this.controlCode+this.areaCode.getCode()+this.animalCode1+this.animalCode2;  
     }   
	
	
	
}
